Selenium Interview Questions and Answers (2026)

TL;DR: This guide covers 80 Selenium interview questions for 2026 across beginner, intermediate, and advanced levels, spanning WebDrivers, locators, XPath, POM, TestNG, CI/CD integration, and automation best practices.

Selenium is among the most in-demand automation testing frameworks in software development today, and hiring managers know exactly what to ask QA engineers and SDETs about it during interviews.

According to 6sense, Selenium ranks #2 with an estimated 23.06% market share in testing and QA technologies in 2026. And over 49,358 companies worldwide have adopted Selenium as their primary testing tool.

This guide compiles interview questions for Selenium and Java that mirror what real technical interviewers ask, from foundational and advanced concepts such as:

  • Selenium IDE, RC, WebDriver, and Grid components
  • Waits, navigation commands, and exception handling
  • XPath (absolute vs. relative) and CSS Selectors
  • Page Object Model (POM) and Object Repository
  • TestNG integration and CI/CD pipeline setup

Beginner-Level Selenium Interview Questions for 2026

These beginner-level Java Selenium interview questions focus on suite components (IDE, RC, WebDriver, and Grid), locator types, Selenese commands, implicit and explicit waits, etc.

1. What are the Selenium suite components?

The Selenium suite has the following components.

  • Selenium IDE

It is a Firefox/Chrome plug-in designed to speed up the creation of automation scripts. It records the user actions on the web browser and exports them as a reusable script.

  • Selenium Remote Control (RC)

RC server allows users to write application tests in various programming languages. This server accepts the commands from the test script and sends them to the browser as Selenium core JavaScript commands. The browser then behaves accordingly.

  • Selenium WebDriver

WebDriver is a programming interface that helps create and run test cases. It provides for acting on web elements. Unlike RC, WebDriver does not require an additional server and interacts natively with the browser applications.

  • Selenium Grid

The grid was designed to distribute commands to different machines simultaneously. It enables parallel execution of tests across different browsers and operating systems. It is exceptionally flexible and is integrated with other suite components for simultaneous execution.

2. Mention the advantages of using Selenium as an automation tool.

Selenium is an automation tool with unique benefits that give it a competitive edge over others, including open source, multi-language support, platform and browser support, framework availability and flexibility, reusability, and integrated and parallel test execution.

3. What is test automation or automation testing?

Test automation, or Selenium automation testing, is the process of using specialized software to control test execution and compare results with expected outcomes.

Automation testing can help reduce the time, cost, and effort required to test software applications by automating repetitive tasks and allowing testers to focus on more critical test cases.

4. What are the advantages of automation testing?

There are many advantages of automation testing.

  • It can save you time and effort
  • It can speed up testing by automating repetitive tasks
  • It can improve test accuracy
  • It can enhance test coverage

5. What is Selenese? How is it classified?

Selenese is the set of Selenium commands used to test your web application. The tester can test broken links, UI elements, Ajax functionality, alerts, windows, list options, and much more using Selenese.

Selenium Commands

Image Representation: Selenium Commands

  • Action: Commands that interact directly with the application
  • Accessors: Allow the user to store certain values in a user-defined variable
  • Assertions: Verifies the current state of the application with an expected state

6. What are the limitations of Selenium testing?

  • Unavailability of reliable tech support
  • Tests web applications only
  • Limited support for image testing
  • No built-in reporting and test management
  • It may require knowledge of programming languages

7. What is the difference between Selenium 3.0 and Selenium 4.0?

Selenium 4.0, released in 2021, is a significant upgrade over Selenium 3.0; the differences span protocol architecture, locator capabilities, Grid setup, and Frontend DevTools access.

Feature

Selenium 3.0

Selenium 4.0

Protocol

JSON Wire

Native W3C WebDriver

Grid

Hub & Node setup

Unified jar, Docker support

Locators

ID, XPath, CSS

Adds Relative Locators

DevTools

Not available

Built-in CDP support

Window Handling

Workarounds needed

Native newWindow() API

Performance

Slower, flaky

Faster, more stable

8. What does Selenium support for testing types?

Selenium supports Regression testing and Functional testing.

Regression testing is the re-execution of previously executed test cases to ensure existing functionality continues to work. The steps involved are:

  • Re-testing: All tests in the existing test suite are executed. It proves to be very expensive and time-consuming.
  • Regression test selection: Tests are classified as feature, integration, and end-to-end tests. In this step, some of the tests are selected.
  • Prioritization of test cases: The selected test cases are prioritized based on business impact and critical functionalities.

Functional testing involves verifying every function of the application with the required specifications. The following are the steps involved:

  • Identify test input
  • Compute test outcome
  • Execute test
  • Compare the test outcome with the actual outcome
Also Read: Types of Automation Testing

9. What are the different types of annotations used in Selenium?

Selenium itself does not define annotations; test frameworks such as TestNG or JUnit do. Common TestNG annotations used with Selenium include:

  • @Test: This annotation is used to mark a method as a test method
  • @BeforeMethod: This annotation is used to execute a method before each test method
  • @AfterMethod: This annotation is used to execute a method after each test method
  • @BeforeClass: This annotation is used to execute a method before the first test method

Other common annotators include:

  • @AfterClass
  • @BeforeSuite
  • @AfterSuite
  • @BeforeTest
  • @AfterTest
  • @DataProvider
  • @Parameters

10. What is the same-origin policy, and how is it handled?

The same-origin policy is a security feature. According to this policy, a web browser allows scripts from one webpage to access the contents of another webpage, provided both pages have the same origin. The origin refers to a combination of the URL scheme, hostname, and port number.

The same-origin policy prevents a malicious script on one page from accessing sensitive data on another webpage.

11. Mention the types of Web locators.

The Locator is a command that tells Selenium IDE which GUI elements (e.g., Text Boxes, Buttons, Check Boxes, etc.) it needs to operate on. Locators specify the area of action.

1. Locator by ID: It takes a string parameter, which is a value of the ID attribute, and returns the object to the findElement() method.

  • driver.findElement(By.id(“user”));

2. Locator by the link: If your targeted element is a link text, then you can use the by.linkText locator to locate that element.

  • driver.findElement(By.linkText(“Today’s deals”)).click();

3. Locator by Partial link: The target link can be located using a portion of text in a link text element.

  • driver.findElement(By.linkText(“Service”)).click();

4. Locator by Name: The first element with the name attribute value matching the location will be returned.

  • driver.findElement(By.name(“books”).click());

5. Locator by TagName: Locates all the elements with the matching tag name

  • driver.findElement(By.tagName(“button”).click());

6. Locator by classname: This finds elements based on the value of the CLASS attribute. If an element has many classes, then this will match against each of them.

  • driver.findElement(By.className(“inputtext”));

7. Locator by XPath: It takes a parameter of String, an XPATHEXPRESSION, and returns an object to the findElement() method.

  • driver.findElement(By.xpath(“//span[contains(text(),’an account’)]”)).getText();

8. Locator by CSS Selector: Locates elements based on the driver’s underlying CSS selector engine.

  • driver.findElement(By.cssSelector(“input#email”)).sendKeys(“myemail@email.com”);

12. What types of waits does WebDriver support?

1. ImplicitWait commands Selenium to wait for a certain amount of time before throwing a “No such element” exception.

  • driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

2. An ExplicitWait is used to tell the WebDriver to wait for specific conditions before throwing an "ElementNotVisibleException" exception.

  • WebDriverWait wait = new WebDriverWait(WebDriver Reference, TimeOut);

3. FluentWait is used to tell WebDriver to wait for a condition and the frequency at which we want to check it before throwing an "ElementNotVisibleException" exception.

  • Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);


Image Representation: Types of Wait

13. Mention the types of navigation commands.

  • driver.navigate().to("https://www.ebay.in/"); - Navigates to the provided URL
  • driver.navigate().refresh(); - This method refreshes the current page
  • driver.navigate().forward(); - This method does the same operation as clicking on the Forward Button of any browser; it neither accepts nor returns anything
  • driver.navigate().back(); - This method performs the same operation as clicking the Back Button in any browser; it neither accepts nor returns anything

14. What is the major difference between driver.close() and driver.quit()?

Method

What It Does

Scope

driver.close()

Closes the current browser window in focus

Only the active window

driver.quit()

Closes all open browser windows and ends the WebDriver session

Entire browser session

15. What makes Selenium such a widely used testing tool? Give reasons.

  • Selenium is widely used because it provides simple and consistent APIs across multiple programming languages
  • Selenium can test web applications across browsers such as Firefox, Opera, Chrome, and Safari
  • The test code can be written in various programming languages, such as Java, Perl, Python, and PHP
  • Selenium is platform-independent and can be deployed on various operating systems, such as Windows, Linux, and macOS
  • Selenium can be integrated with third-party testing frameworks such as JUnit and TestNG for test management
Master the latest automation testing platforms such as Selenium WebDriver, Appium, AutoIT, TestNG, etc., by opting for our AI-Powered Automation Test Engineer Program. Become an automation testing expert in just 6 months!

16. Why is it advised to select Selenium as a web application or system testing tool?

  • Selenium is an open-source, portable tool and freeware
  • It supports many operating systems, such as Linux, Unix, Macintosh, and Windows
  • Selenium supports Chrome, Opera, and Safari
  • It supports many languages, including Perl, Java, Python, Ruby, Groovy, JavaScript, VBScript, etc
  • Selenium can be used for application testing on iPhone, Android, and BlackBerry devices
  • It helps integrate it with the ANT or Maven framework for source code compilation
  • It requires less CPU and RAM consumption for script execution

17. What is an exception test in Selenium?

The exception test in Selenium is an exception you expect to be thrown within a test class. If you have written a test case so that it should be thrown as an exception, then you can use the test annotation and specify the exception in the parameters.

18. How to wait until a web page has been loaded completely in Selenium?

One approach is to use the "implicit wait" command in Selenium, which instructs the web driver to wait a certain amount of time before throwing an error if the element is not found or loaded.

Another option is to use the "explicit wait" command for a specific element to appear on the page before proceeding with the script.

19. What is Selenium WebDriver?

Selenium WebDriver is the main tool in the Selenium suite for automating web browsers. It interacts directly with the browser without requiring a separate server, making it faster than the older Selenium RC.

WebDriver supports multiple browsers and multiple languages, such as Java, Python, and C#. It allows testers to simulate real user actions such as clicking, typing, scrolling, and navigating across pages.

20. Is Selenium WebDriver a library?

No. Selenium WebDriver is not just a simple library. It is an API that provides a set of classes and interfaces to control browsers. It provides language bindings (such as Java or Python) that communicate with browser-specific drivers, such as ChromeDriver or GeckoDriver. This makes it more than a standalone library, since it acts as the link between your test scripts and the browser.

21. Which browsers/drivers are supported by Selenium Webdriver?

Selenium WebDriver supports several popular web browsers, including Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, and Opera.

22. What will happen if I execute this command: driver.get

In Selenium, calling driver.get("https://...") makes the browser navigate to the given URL and (in most bindings) waits until the page finishes loading (i.e., the document is loaded) before the next line runs.

If you execute just driver.get without parentheses or a URL, you’re not navigating anywhere; you’re only referencing the method object (typically, no action happens; in Python, it would just be a bound method reference).

23. What is an alternative option to driver.get() method to open a URL in Selenium Web Driver?

An alternative option for the driver.get() method to open a URL in Selenium Web Driver is to use the driver.navigate().to() method.

24. Is it possible to test APIs or web services using Selenium WebDriver?

We cannot test APIs or web services with Selenium WebDriver, as it is designed for testing web-based applications.

25. Mention different ways of locating an element in Selenium?

The various ways of locating an element in Selenium are by ID, by name, by class name, by tag name, by link text, by partial link text, by CSS selector, and by XPath.

26. How can we move to the nth-child element using XPath?

We can move to the nth-child element using XPath using the following expression: (//parent-element/*)[n].

Use this structure to answer any Selenium concept question in an interview:

"[Selenium concept] is [one-line definition]. It works by [how it functions internally]. A real-world example is [practical use case], where it helps [specific outcome]. Without it, you'd face [problems it solves]."

Example applied to Explicit Wait:

"Explicit Wait in Selenium is a condition-based pause that holds test execution until a specific element state is met or a timeout is reached. It works by polling the DOM at set intervals using ExpectedConditions until the condition turns true.

A real-world example is a login button that activates only after form validation. Explicit Wait waits until the button is actually clickable. And without it, you would get random test failures when something loads a little slower than the script anticipates."

Intermediate Level Selenium Interview Questions for 2026

These interview questions for Selenium Java move beyond theory and test your hands-on automation skills. into hands-on WebDriver usage. Covering sendKeys(), scrolling with JavaScript, handling pop-ups, taking screenshots, working with window handle, and more.

27. How to type text in an input box using Selenium?

sendKeys() is the method used to type text in input boxes.

Consider the following example:

  • WebElement email = driver.findElement(By.id(“email”)); - Finds the “email” text using the ID locator
  • email.sendKeys(“abcd.efgh@gmail.com”); - Enters text into the URL field
  • WebElement password = driver.findElement(By.id(“Password”)); - Finds the “password” text using the ID locator
  • password.sendKeys(“abcdefgh123”); - Enters text into the password field

28. How to click on a hyperlink in Selenium?

  • driver.findElement(By.linkText(“Today’s deals”)).click();

The command finds the element by its link text and then clicks it, after which the user is redirected to the corresponding page.

  • driver.findElement(By.partialLinkText(“Service”)).click();

The above command finds the element based on the substring of the link provided in the parentheses, and the partialLinkText() finds the web element.

29. How to scroll down a page using JavaScript?

scrollBy() method is used to scroll down the webpage.

General syntax:

executeScript("window.scrollBy(x-pixels,y-pixels)");

First, create a JavaScript object

  • JavascriptExecutor js = (JavascriptExecutor) driver;

Launch the desired application

  • driver.get(“https://www.amazon.com”);

Scroll down to the desired location

  • js.executeScript("window.scrollBy(0,1000)"); 

The window is scrolled vertically by 1000 pixels

30. How to assert the title of a webpage?

Get the webpage title and store it in a variable.

String actualTitle = driver.getTitle();

Type in the expected title

String expectedTitle = “abcdefgh";

Verify if both of them are equal

if(actualTitle.equalsIgnoreCase(expectedTitle))
System.out.println("Title Matched");
else
System.out.println("Title didn't match");

31. How do you hover over a web element with a mouse?

The actions class utility is used to hover over a web element in Selenium WebDriver.

Instantiate the Actions class.

Actions actions = new Actions(driver);

In this scenario, we hover over the search box of a website

actions.moveToElement(driver.findElement(By.id("id of the searchbox"))).perform();

32. How to retrieve CSS properties of an element?

The getCssValue() method retrieves CSS properties of any web element.

General Syntax:

driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);

Example:

driver.findElement(By.id(“email“)).getCssValue(“font-size”);

33. What is POM (Page Object Model)?

Every webpage in the application has a corresponding page class that locates web elements and performs actions on them. Page Object Model is a design pattern that helps create object repositories for the web elements. POM improves code reusability and readability. Multiple test cases can be run on the object repository.

Page Object Model

Image Representation: Page Object Model

34. Can Captcha be automated?

No, Selenium cannot automate Captcha. Well, the whole concept of Captcha is to prevent bots and automated programs from accessing sensitive information, which is why Selenium cannot automate it. The automation test engineer has to manually type the captcha, while other fields can be filled automatically.

35. How does Selenium handle Windows-based pop-ups?

Selenium was designed to handle web applications. Selenium does not natively support Windows-based features. However, third-party tools such as AutoIT and Robot can be integrated with Selenium to handle pop-ups and other Windows-based features.

Learn 15+ In-Demand Tools and Skills!

AI-Powered Automation Test Engineer ProgramExplore Program
Learn 15+ In-Demand Tools and Skills!

36. How to take screenshots in WebDriver?

  • TakesScreenshot interface can be used to take screenshots in WebDriver
  • getScreenshotAs() method can be used to save the screenshot
  • File scrFile = ((TakeScreenshot)driver).getScreenshotAs(OutputType.FILE);

37. Why do testers choose Selenium over QTP?

Selenium is an open-source, free automation testing tool, while QTP is a licensed tool that requires a significant investment. Selenium supports multiple programming languages and is cross-platform compatible.

38. What are the data-driven framework and the keyword-driven framework?

A data-driven framework is a test automation framework that separates the test data from the test script. It allows testers to write automated tests that are independent of test data.

A keyword-driven framework separates test logic from test implementation by using predefined keywords (e.g., Click, EnterText, Navigate, Verify). Test cases are written in tabular form (e.g., in Excel or a similar tool), with each step represented by a keyword mapped to the underlying automation code.

39. What is the difference between getwindowhandles() and getwindowhandle()?

Method

What It Returns

Return Type

Scope

getWindowHandle()

Unique ID of the current browser window

String

Current window only

getWindowHandles()

Unique IDs of all open browser windows

Set<String>

All open windows

40. What is a Selenium Maven project?

A Selenium Maven project is a software project that uses Maven to manage the project's dependencies and build process.

41. What is an Object Repository?

An Object Repository is a centralized location where testers can store all web elements used in the test automation framework, such as buttons, text boxes, and links.

42. What exactly does a WebElement in Selenium mean, and how is it used?

The WebElement interface in Selenium represents an HTML element on a web page. It provides methods for interacting with web elements, such as clicking, entering text, and retrieving values. It identifies and manipulates web elements during automated testing.

Advanced Level Selenium Interview Questions for 2026

These advanced Selenium interview questions with Java test real-world implementation depth, including XPath absolute vs. relative paths, JavaScriptExecutor, dropdown handling with the Select class, drag-and-drop using the Actions class, and more.

43. Is there a way to type in a textbox without using sendKeys()?

Yes! Text can be entered into a textbox using JavaScriptExecutor

JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById(‘email').value=“abc.efg@xyz.com”);

44. How to select a value from a dropdown in Selenium WebDriver?

Select class in WebDriver is used to select and deselect options in a dropdown. The Select type can be initialized by passing the dropdown web element as a parameter to its constructor.

WebElement testDrop = driver.findElement(By.id("testingDropdown"));  
Select dropdown = new Select(testDrop);
WebDriver offers three ways to select from a dropdown:
selectByIndex: Selection based on index starting from 0
dropdown.selectByIndex(5);
selectByValue: Selection based on value
dropdown.selectByValue(“Books”);
selectByVisibleText: Selection of an option that displays text matching the given argument
dropdown.selectByVisibleText(“The Alchemist”);

45. What does the switchTo() command do?

The switchTo() command switches between windows, frames, or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”.

Get the window handle of the window you wish to switch to

String  handle= driver.getWindowHandle();
Switch to the desired window
driver.switchTo().window(handle);

46. How to upload a file in Selenium WebDriver?

You can achieve this by using sendkeys() or the Robot class method.

1. Locate the text box, set the file path using sendKeys(), and click the submit button

2. Go to the browse button and select

WebElement browse =driver.findElement(By.id("uploadfile"));

3. Pass the path of the file to be uploaded using the sendKeys method

browse.sendKeys("D:\\SeleniumInterview\\UploadFile.txt");

47. How to set the browser window size in Selenium?

The window size can be maximized, set, or resized.

To maximize the window:

driver.manage().window().maximize();

To set the window size:

Dimension d = new Dimension(400,600);

driver.manage().window().setSize(d);

48. When do we use findElement() and findElements()?

findElement() is used to access any single element on the web page. It returns the object of the first matching element of the specified locator.

General syntax:

WebElement element = driver.findElement(By.id(example));

findElements() returns all elements on the current web page that match the specified locator. All the matching elements would be fetched and stored in the list of Web elements.

General syntax:

List <WebElement> elementList = driver.findElements(By.id(example));

49. What is a pause on an exception in Selenium IDE?

The user can use this feature to handle exceptions by clicking the pause icon in the top right corner of the IDE. When the script encounters an exception, it pauses the current statement and enters debug mode. The entire test case does not fail, and hence, the user can rectify the error immediately. 

50. How to login to any site if it is showing an Authentication Pop-Up for Username and Password?

To handle authentication pop-ups, verify their appearance, and then handle them using an explicit wait command.

  • Use the explicit wait command

WebDriverWait wait = new WebDriverWait(driver, 10);

  • The alert class is used to verify the alert

Alert alert = wait.until(ExpectedConditions.alertIsPresent());

  • Once verified, provide the credentials

alert.authenticateUsing(new UserAndPassword(<username>, <password>));

Handle Authentication Pop-ups

Image Representation: Handle Authentication Pop-ups

51. What is the difference between single and double slash in XPath?

Slash

Type

Key Behavior

Example

/

Absolute XPath

Starts from the root; selects direct child nodes only

/html/body/div[2]/div[1]/div[1]/a

//

Relative XPath

Searches anywhere in the document; selects descendant nodes

//div[@class="qa-logo"]/a

Learn From The Best Mentors in the Industry!

AI-Powered Automation Test Engineer ProgramExplore Program
Learn From The Best Mentors in the Industry!

Top Selenium Interview Questions for Experienced

Here are some of the top interview questions and answers on Selenium for experienced professionals that can help them prepare better for their interviews:

52. How do you find broken links in Selenium WebDriver?

When we use a driver and call the get() method to navigate to a URL, it returns a status of 200-OK.

200 – OK denotes that the link is working and it has been obtained. If any other status is obtained, it indicates that the link is broken.

Some of the HTTP status codes are:

  • 200 – valid Link
  • 404 – Link Not Found
  • 400 – Bad Request
  • 401 – Unauthorized
  • 500 – Internal error
  1. As a starter, obtain the links from the web application, then check each link's status individually
  2. Navigate to the interested webpage, e.g., www.amazon.com
  3. Collect all the links from the webpage. All the links are associated with the Tag ‘a‘
List<WebElement> links = driver.findElements(By.tagName("a"));

//Create a list of WebElement types to store all the Link elements.
for(int i=0; i<links.size(); i++) {
WebElement element = links.get(i);
String url=element.getAttribute("href");
verifyLink(url);  }

//Now Create a Connection using URL object( i.e ., link)
URL link = new URL(urlLink);

//Connect using the Connect Method
HttpURLConnection httpConn =(HttpURLConnection)link.openConnection();

//Use getResponseCode () to get the response code
if(httpConn.getResponseCode()!= 200)
Through exception, if any error occurred
System.out.println(“Broken Link”);

53. Name some of the commonly used automation testing tools for functional automation.

  • QTP
  • Test Complete
  • RFT
  • Silk Test

54. Name some of the commonly used automation testing tools for non-functional automation.

  • LoadRunner
  • JMeter
  • WebLoad
  • Neoload
  • Silk Performer
  • HP Performance Center
  • Gatling

55. List out some of the automation tools that could be integrated with Selenium to achieve continuous testing.

Some of the automation tools that could be integrated with Selenium to achieve continuous testing are:

  • Jenkins
  • Travis CI
  • CircleCI
  • AWS CodePipeline
  • Azure DevOps
  • Bitbucket Pipelines

56. What do you mean by the assertion in Selenium?

An assertion is a way to test whether a particular condition is true or false. In Selenium, assertions verify the state of elements on a page or the results of an action.

Assertions can be used to check whether an element is present or absent, what its value is, or what its text is. Assertions can also be used to check that an element is visible or hidden.

Assertions are an important part of Selenium testing, as they enable you to verify that your application's state meets your expectations. Without assertions, it would be difficult to know whether your tests are passing or failing.

57. Explain the difference between assert and verify commands.

Command

If Condition is True

If Condition is False

assert

Execution continues

Execution stops immediately

verify

Execution continues

Execution continues; logs an error message

58. What do you mean by XPath?

XPath is a language for addressing parts of an XML document. XSLT and other XML-related technologies use it to access data within XML documents. XPath can navigate through elements and attributes in an XML document. XPath is a core component of the XSLT standard and is crucial for processing XML documents.

59. Explain Absolute XPath, Relative XPath, and how attributes are used in XPath.

XPath has two main types of expressions: absolute and relative. Absolute expressions always start with a forward slash (/), which indicates the document's root element. Relative expressions do not start with a forward slash and are relative to the current context.

Attributes are another important part of XPath. Attributes are added to elements and can contain valuable information about that element. You must use the at sign (@) followed by the attribute name to access an attribute.

60. What is the difference between type keys and type commands?

Feature

Type

TypeKeys

Behavior

Clears existing text and enters a new value

Simulates real keyboard typing

Existing text

Replaced

Appended

Key events triggered

Limited

Yes (keyup, keydown, keypress)

Use case

Simple text entry

When keyboard events matter

61. What is the difference between "type" and "typeAndWait" commands?

The "type" command is used to enter text into a field on a web page. The "typeAndWait" command also enters text into a field but waits for the page to load before proceeding to the next command. This can be useful if you are unsure whether or not the text you entered will cause the page to refresh.

The main difference between the "type" and "typeAndWait" commands is that "type" does not wait for the page to reload, whereas "typeAndWait" does. If you are unsure whether or not the text you are entering will cause the page to refresh, it is best to use the "typeAndWait" command. This way, you can be sure that the next command will not be executed until the page has finished loading.

62. What is the main disadvantage of implicit wait?

The main disadvantage of implicit wait is that it can slow down your tests. This is because the implicit wait time is set to 0 by default. As such, if an element is not found immediately, your test will keep trying to find it for the implicit wait time.

This can significantly increase the time required for your test suite. Another disadvantage of implicit wait is that it can cause your tests to fail if the element you are waiting for takes longer to appear than the implicit wait time. Finally, the implicit wait can make your tests less reliable by introducing flakiness.

63. How can we launch different browsers in Selenium WebDriver?

We can launch different browsers in Selenium WebDriver using several methods. For example, we can use the setWebDriver() method to specify the path to the browser's executable file.

Alternatively, we can use the addCustomProfilePreference() method to add a custom profile preference for the browser. Finally, we can launch the browser using the launchBrowser() method.

64. Write a code snippet to launch the Firefox browser in WebDriver.

public class FirefoxDriver {
private WebDriver driver;
public FirefoxDriver() {
this.driver = new FirefoxDriver();
}
public void get(String url) {
this.driver.get(url);
}

Assuming you have already downloaded and installed Firefox, you must next write a code snippet to launch Firefox in WebDriver. The code snippet for launching the Firefox browser is given below:

driver = new FirefoxDriver();

driver.get("http://www.google.com");

65. Write a code snippet to launch the Chrome browser in WebDriver.

WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
String url = "https://www.google.com";
driver.get(url);
wait.until(ExpectedConditions.titleContains("Google"));
System.out.println("Page title is: " + driver.getTitle());
driver.quit();

This code snippet will launch Chrome, navigate to Google.com, and print the page title to the console.

Earn an industry-recognized course completion certificate and get noticed by top hiring companies by opting for our AI-Powered Automation Test Engineer Program. Enroll NOW!

66. How do you perform drag and drop operations in WebDriver?

When using WebDriver, you can perform drag-and-drop operations using the Actions class. This class provides several methods for performing actions such as clicking, dragging, and dropping. To use the Actions class, you first need to instantiate it with a WebDriver instance:

Actions actions = new Actions(driver);

Once you have an Actions instance, you can use the dragAndDrop() method to perform a drag and drop operation. This method takes two WebElements as arguments: the element toDrag, and the element toDrop. For example, to drag an element with the id "draggable" and drop it on an element with the id "droppable", you would do the following:

  • WebElement draggable = driver.findElement(By.id("draggable"));
  • WebElement droppable = driver.findElement(By.id("droppable"));
  • actions.dragAndDrop(draggable, droppable).perform();

You can also use the clickAndHold() and release() methods to perform a drag and drop operation. The clickAndHold() method takes a WebElement as an argument and "grabs" it, while the release() method releases the element. For example:

actions.clickAndHold(draggable).release(droppable).perform();

You can also chain together multiple Action methods to create more complex interactions. For example, the following code will first move to the draggable element, then click and hold it, move to the droppable element, and finally release it:

actions.moveToElement(draggable).clickAndHold().moveToElement(droppable).release().perform();

67. What are the different web page refresh methods in WebDriver?

Method

Code Snippet

Description

navigate().refresh()

driver.navigate().refresh();

Refreshes the current page

get() with current URL

driver.get(driver.getCurrentUrl());

Reloads the page by reloading the current URL

navigate().to() with current URL

driver.navigate().to(driver.getCurrentUrl());

Similar to get(), reloads current page

sendKeys(Keys.F5)

driver.findElement(By.tagName("body")).sendKeys(Keys.F5);

Simulates F5 key press

68. How to invoke an application in WebDriver?

When using WebDriver, you can launch applications by calling the "get" method on the driver instance or using the "navigate" method. Applications can also be invoked using a third-party tool such as Selenium IDE.

However, doing so requires that you have the application URL available beforehand. When using the "get" method, you simply need to pass in the application URL as a string.

69. Is there an HtmlUnitDriver for .NET?

Yes. HtmlUnitDriver is mainly a headless browser driver for Java, but .NET users can achieve similar functionality through Selenium’s .NET bindings. While it isn’t as commonly used today as Chrome or Firefox headless modes, HtmlUnitDriver (or its .NET equivalents) can still be used for fast, lightweight test execution without opening a real browser.

70. How can you redirect browsing from a browser through a proxy?

There are a few ways to redirect browser traffic through a proxy. One way is to use a web proxy. Web proxies can be used to access websites that your network administrator may block.

Another way to redirect browsing is to use a Virtual Private Network (VPN). VPNs can encrypt your traffic and route it through a proxy server.

Finally, you can use a browser extension to redirect your traffic. Browser extensions are useful if you want to bypass proxy servers configured in your network settings.

71. Explain the pause feature in Selenium IDE.

The pause feature in Selenium IDE allows the tester to add a pause between the execution of two commands. It is used to slow down test execution to allow better observation of the test flow.

72. How do you handle a frame in WebDriver?

Frames are handled using the switchTo().frame() method in WebDriver. You can switch by index, name/id, or WebElement. After interacting with elements inside the frame, switch back using driver.switchTo().defaultContent() or parentFrame() to return to the main page context.

73. Mention the types of listeners in TestNG

TestNG supports three types of listeners:

  • Test listeners: They listen to test execution and allow us to perform actions before or after executing a test case.
  • Suite listeners: They listen to the suite execution and allow us to perform actions before or after the execution.
  • Method listeners: They monitor the execution of individual test methods and allow us to perform actions before or after each test method.

74. Mention important details of different types of frameworks, and also regarding the connection of Selenium with Robot Framework.

Different sets of frameworks are available, which can be used with Selenium:

  • Data-Driven Framework: It uses external data sources, such as CSV or Excel files, to drive test execution.
  • Keyword-Driven Framework: It uses specific keywords to execute test cases.
  • Hybrid Framework: It is a combination of both Data-Driven and Keyword-Driven frameworks.

Selenium can be connected with Robot Framework using the Selenium2Library. The Selenium2Library is a Robot Framework test library that allows us to control web browsers using Selenium WebDriver.

75. Mention details of the basic steps of Selenium testing and mention the widely used commands via a practical application.

The basic steps of Selenium testing are:

  • Launch a web browser
  • Navigate to a web page
  • Locate web elements
  • Perform actions on web elements
  • Verify the results

Some widely used Selenium commands are:

  • get() method: to launch the web page
  • findElement() method: to locate the web element
  • click() method: to click on the web element
  • sendKeys() method: to enter text into the web element
  • getText() method: to retrieve the text from the web element

76. What is Jenkins exactly, and what are its advantages with Selenium?

Jenkins is an open-source CI/CD automation server. Using Jenkins with Selenium provides the following benefits:

  • Automatically run Selenium tests when code is committed to the repository
  • Parallel execution of Selenium tests on multiple machines to reduce the execution time
  • Integration with other tools such as JIRA, GitHub, and Slack to provide notifications and status updates

Tricky Selenium Interview Questions

These questions test conceptual depth, covering subtle distinctions, methods for handling web elements, stale-element exceptions, and more.

77. Explain the methods used to handle dynamic web elements using Selenium.

Dynamic web elements can be handled using different methods such as XPath, CSS selectors, and the Explicit wait mechanism in Selenium. You can use these methods to locate and perform actions on the dynamic elements.

78. How do you deal with stale element exceptions in Selenium?

Stale element exceptions occur when the element you are interacting with is no longer attached to the DOM or has been modified. To handle this exception, you can refresh the page or try locating the element again with a different locator strategy.

79. How do you simulate a browser back button click in Selenium?

You can simulate a browser back button click in Selenium using the navigate() method.back() method. This method navigates back to the previous page in the browser's history.

80. How do you handle alerts in Selenium?

Alerts can be handled using the Alert interface in Selenium. You can switch to the alert using the switchTo().Use the alert() method to display an alert, and perform actions such as accepting or dismissing it using the accept() or dismiss() methods.

In a Reddit thread under r/softwaretesting, engineers who actively conduct Selenium interviews shared what they actually look for:

"Know your locators and be able to explain why you'd choose one over another. Relative vs. absolute XPath will come up. Expect a live coding task, something like automating a login screen. They want to see if you can justify your approach, not just simply recite it."

Conclusion

For those looking to enhance their software testing skills, we recommend you check our Automation Testing Master's Program. This course can help you acquire the right skills and become job-ready.

The training is designed to teach developers and testers how to automate web applications with a robust framework, integrate it into an organization's DevOps processes, and master essential concepts such as TestNG, Selenium IDE, and Selenium Grid.

About the Author

Kusum SainiKusum Saini

Kusum Saini is the Director - Principal Architect at Simplilearn. She has over 12 years of IT experience, including 3.5 years in the US. She specializes in growth hacking and technical design and excels in n-layer web application development using PHP, Node.js, AngularJS, and AWS technologies.

View More
  • Acknowledgement
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, OPM3 and the PMI ATP seal are the registered marks of the Project Management Institute, Inc.
  • *All trademarks are the property of their respective owners and their inclusion does not imply endorsement or affiliation.
  • Career Impact Results vary based on experience and numerous factors.